<div class="main-right-content">
    <div th:include="person/index_search"></div>
    <blockquote class="site-text layui-elem-quote margin-top-10">
        <a data-open="/person/add" class="layui-btn layui-btn-normal">添加用户</a>
    </blockquote>
    <table class="layui-hide" id="person-list" lay-filter="person-list"></table>
</div>

<script type="text/html" id="person-list-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use('table', function () {
        var table = layui.table;
        table.render({
            elem: '#person-list'
            , url: '/person/list'
            , method: 'post'
            , limit: 10
            , cellMinWidth: 80
            , cols: [[
                {type: 'checkbox'}
                , {field: 'id', title: '编号', sort: true}
                , {field: 'personBirthDay', title: '学院'}
                , {field: 'personDeathDay', title: '贷款人数', sort: true}
                , {field: 'personName', title: '老师名字'}
                , {field: 'personEnglishName', title: '辅导员名字'}
                , {field: 'personBiography', title: '贷款人数', sort: true}
                , {field: 'personBirthPlace', title: '班级指标', sort: true}
                , {field: 'personBirthDay', title: '辅导员编号'}
                , {field: 'personName', title: '学院', sort: true}
                , {title: '操作', toolbar: '#person-list-bar', align: 'center'}
            ]]
            , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'] //自定义分页布局
                , groups: 10 //只显示 1 个连续页码
            }
            , request: {
                pageName: 'pageNum' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
        });

        //监听工具条
        table.on('tool(person-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.alert('用户信息：<br>' + JSON.stringify(data))
            } else if (obj.event === 'del') {
                var json = {
                    url: "/person/ajaxDelete",
                    param: "ids#" + data.id,
                    msg: "确定要删除该用户吗？"
                }
                $.layui.delete(json);
            } else if (obj.event === 'edit') {
                var url = "/person/edit/" + data.id;
                $.layui.edit(url);
            }
        });

        var $ = layui.$, active = {
            search: function () {
                var json = $('#layui-table-form').formToJson();
                //执行重载
                table.reload('person-list', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: json
                });
            }
        };

        $('#layui-table-form #btnQuery').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>
